package com.ws.user.user.web;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.ws.common.easyui.util.Page;
import com.ws.common.easyui.util.PageUtils;
import com.ws.user.user.entity.UserRole;
import com.ws.user.user.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/user/user/role")
@Controller
public class UserRoleWeb {


    @Autowired
    IUserRoleService userRoleService;

    @RequestMapping("{type}")
    public String list(@PathVariable String type){
        return  null;
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(UserRole userRole,Page page){
        List<UserRole> userRoles=userRoleService.list(userRole,page);
        return PageUtils.getEasyUiList(userRoles);
     }

    @RequestMapping("read")
    @ResponseBody
    public Object read(UserRole userRole){
        if(StrUtil.isNotEmpty(userRole.getId())){
            userRole= userRoleService.read(userRole.getId());
        }
        return  userRole;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(UserRole userRole){
        Integer count=userRoleService.save(userRole);
        return  count;
     }

    @RequestMapping("/delete")
    @ResponseBody
    public Integer delete(String id){
        return  userRoleService.delete(id);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(UserRole userRole){
        Integer count=userRoleService.insert(userRole);
        return  count;
    }

    @RequestMapping("/insertSelective")
    @ResponseBody
    public Object insertSelective(UserRole userRole){
        return userRoleService.insertSelective(userRole);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(UserRole userRole){
        return userRoleService.update(userRole);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public Object listByMap(){
        return  userRoleService.listAll();
    }
}
